//
//  RealnameManagementVC.m
//  Toyota
//
//  Created by ld on 2024/6/25.
//

#import "RealnameManagementVC.h"
#import "PopUpTipsView.h"
#import <LSTPopView.h>
#import "Definition.h"
#import "Helper.h"
@interface RealnameManagementVC ()
@property (nonatomic, strong) UIButton * relieveBtn;
@end

@implementation RealnameManagementVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUI];
    // Do any additional setup after loading the view.
}

- (void)initUI{
    NSArray * keyArr= @[@"真实姓名", @"证件号码"];
    NSArray * valArr = @[@"高*强", @"1****************2"];
    
    for (int i = 0; i < keyArr.count; i++) {
        UIView * cellBgView = [[UIView alloc]initWithFrame:CGRectMake(21, 10 + 55 * i, ScreenWidth - 42, 55)];
        [cellBgView borderViewForColor:kColorEDEDED borderWidth:1 borderType:(UIBorderSideTypeBottom)];
        [self.view addSubview:cellBgView];
        
        UILabel * keyLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 120, cellBgView.customHeight)];
        keyLab.text = keyArr[i];
        keyLab.textColor = kColor141414;
        keyLab.font = fontSize(15);
        [cellBgView addSubview:keyLab];
        
        UILabel * valLab = [[UILabel alloc]initWithFrame:CGRectMake(keyLab.customRight, 0, cellBgView.customWidth - keyLab.customWidth, cellBgView.customHeight)];
        valLab.text = valArr[i];
        valLab.textColor = kColor141414;
        valLab.font = fontSize(15);
        valLab.textAlignment = NSTextAlignmentRight;
        [cellBgView addSubview:valLab];
    }
    
    //按钮
    _relieveBtn = [[UIButton alloc]init];
    [self.view addSubview:_relieveBtn];
    [_relieveBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.bottom.equalTo(self.view).offset(-CYScalH(70) - CYSafeAreaBottom);
        make.size.mas_equalTo(CGSizeMake(CYScalW(344), CYScalXH(40)));
    }];
    [_relieveBtn setTitle:@"解除实名认证" forState:UIControlStateNormal];
    [_relieveBtn setTitle:@"实名认证解除中" forState:(UIControlStateSelected)];
    [_relieveBtn setBackgroundImage:[UIImage imageWithColor:kColor141414] forState:(UIControlStateNormal)];
    [_relieveBtn setBackgroundImage:[UIImage imageWithColor:kColorC2C2C2] forState:(UIControlStateSelected)];
    [_relieveBtn setBackgroundImage:[UIImage imageWithColor:kColorC2C2C2] forState:UIControlStateDisabled];
    [_relieveBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_relieveBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateSelected)];
    _relieveBtn.titleLabel.font = fontSize(15);
    _relieveBtn.clipsToBounds = YES;
    _relieveBtn.layer.cornerRadius = CYScalW(20);
    [_relieveBtn addTarget:self action:@selector(searchBtnClick) forControlEvents:UIControlEventTouchUpInside];
    
    
    //注意事项
    UIView * tipsView = [[UIView alloc]init];
    tipsView.backgroundColor = [UIColor colorWithHex:0xFFF8D4];
    [self.view addSubview:tipsView];
    // 使用Masonry为yellowView设置约束
    [tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(0);
        make.right.equalTo(self.view).offset(0);
        make.bottom.equalTo(_relieveBtn.mas_top).offset(-CYScalH(10));
    }];
    
    UILabel * tipsLabel = [[UILabel alloc]init];
    tipsLabel.font = fontSize(12);
    tipsLabel.textColor = [UIColor colorWithHex:0xFF6B00];
    tipsLabel.numberOfLines = 0;
    tipsLabel.text = @"如您解除实名认证，则您的车辆将仅能使用紧急呼叫、应急救援等涉及生命安全的功能。";
    tipsLabel.attributedText = [tipsLabel setupAttributeString:tipsLabel.text andFont:fontSize(12) andColor:tipsLabel.textColor andTextAlignment:(NSTextAlignmentLeft) rangeLineHeight:4];
    [tipsLabel sizeToFit];
    [tipsView addSubview:tipsLabel];
    
    [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(tipsView).offset(CYScalW(12));
        make.left.equalTo(tipsView).offset(CYScalW(15));
        make.right.equalTo(tipsView).offset(-CYScalW(15));
        make.bottom.equalTo(tipsView).offset(-CYScalW(12));
    }];
}

#pragma mark 解除实名认证
-(void)searchBtnClick {
    PopUpTipsView * popUpView = [[PopUpTipsView alloc]initWithFrame:CGRectMake(0, 0, CYScalW(280), 200)];
    [popUpView tipsWithTitle:@"解除确认" andContent:@"如您未进行实名认证，则您的车辆将仅能使用紧急呼叫、应急救援等涉及生命安全的功能。\n您确认仍要解除实名制认证?" andContentAlignment:NSTextAlignmentLeft andBtnTitleArr:@[@"确认", @"取消"] andbtnColorArr:@[kColor141414, [UIColor whiteColor]] andBtnBgColorArr:@[[UIColor whiteColor], kColor141414]];
    LSTPopView *popView = [LSTPopView initWithCustomView:popUpView popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    __block LSTPopView *blockFooter = popView;
    popView.popDuration = 0.5;
    popView.hemStyle = LSTHemStyleCenter;
    popView.dismissDuration = 0.5;
    popView.bgAlpha = 0.5;
    [popView pop];
    popView.bgClickBlock = ^{
        [blockFooter dismiss];
    };
    popUpView.customHeight = popUpView.bgV.customBottom;
    popUpView.choicActionBlock = ^(NSString * _Nonnull choiceAction) {
        if ([choiceAction isEqualToString:@"取消"]) {
            [blockFooter dismiss];
        }else if ([choiceAction isEqualToString:@"确认"]) {
            [blockFooter dismiss];
            [self popUpConfirmView];
        }
    };
}

- (void)popUpConfirmView {
    [LSTPopView removeAllPopView];
    PopUpTipsView * popUpView = [[PopUpTipsView alloc]initWithFrame:CGRectMake(0, 0, CYScalW(280), 200)];
    [popUpView tipsWithTitle:@"解除确认" andContent:@"检测到您的车辆正在紧急呼救\n您确认仍要解除实名认证?" andContentAlignment:NSTextAlignmentCenter andBtnTitleArr:@[@"确认", @"取消"] andbtnColorArr:@[kColor141414, [UIColor whiteColor]] andBtnBgColorArr:@[[UIColor whiteColor], kColor141414]];
    LSTPopView *popView = [LSTPopView initWithCustomView:popUpView popStyle:LSTPopStyleFade dismissStyle:LSTDismissStyleFade];
    __block LSTPopView *blockFooter = popView;
    popView.popDuration = 0.5;
    popView.hemStyle = LSTHemStyleCenter;
    popView.dismissDuration = 0.5;
    popView.bgAlpha = 0.5;
    [popView pop];
    popView.bgClickBlock = ^{
        [blockFooter dismiss];
    };
    popUpView.customHeight = popUpView.bgV.customBottom;
    popUpView.choicActionBlock = ^(NSString * _Nonnull choiceAction) {
        if ([choiceAction isEqualToString:@"取消"]) {
            [blockFooter dismiss];
        }else if ([choiceAction isEqualToString:@"确认"]) {
            [blockFooter dismiss];
            [self.relieveBtn setTitle:@"实名认证解除中" forState:(UIControlStateNormal)];
            self.relieveBtn.enabled = NO;
        }
    };
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
